package com.atguigu.spzx.manager.controller.product;

import com.atguigu.spzx.manager.service.product.ProductService;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.entity.product.Product;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mahone
 */
@RestController
@RequestMapping("/admin/product/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 分页查询商品列表
     */
    @GetMapping("/findProductListByPage/{page}/{limit}")
    public Result findProductListByPage(@PathVariable("page" )  Integer pageNum,
                                        @PathVariable("limit") Integer pageSize, ProductDto productDto){
        PageInfo<Product> productPageInfo = productService.findProductListByPage(pageNum,pageSize,productDto);
        return Result.ok(productPageInfo);
    }

    /**
     * 添加商品接口
     * @param product
     * @return
     */
    @PostMapping("/saveProduct")
    public Result saveProduct(@RequestBody Product product){
            productService.insertProduct(product);
            return Result.ok();
    }


    /**
     * 根据id获取信息
     * @param id
     * @return
     */
    @GetMapping("/getProductById/{id}")
    public Result getProductById(@PathVariable("id") Long id){
        Product product = productService.updateProductById(id);
        return Result.ok(product);
    }

    /**
     * 修改信息
     * @param product
     * @return
     */
    @PutMapping("/updateProductById")
    public Result updateProductById(@RequestBody Product product){
        productService.updateProduct(product);
        return Result.ok();
    }


    /**
     * 审核
     * @param id,auditStatus
     * @return
     */
    @GetMapping("/updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable("id") Long id,@PathVariable("auditStatus")Integer auditStatus){
        productService.updateAuditStatus(id,auditStatus);
        return Result.ok();
    }

    /**
     * 上下架
     * @param id
     * @param status
     * @return
     */
    @GetMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable("id") Long id,@PathVariable("status")Integer status){
        productService.updateStatus(id,status);
        return Result.ok();
    }




}
